local julue = fk.CreateSkill{
  name = "zy__julue",
}
local julue_ = {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      local targets = {}
      for _, move in ipairs(data) do
        if move.from then
          local to = move.from
          if to:isKongcheng() and not to.dead and not table.every(move.moveInfo, function (info)
              return info.fromArea ~= Card.PlayerHand end) then
            table.insert(targets, move.from)
          end
        end
      end
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = self.cost_data
    local id
    if #targets > 1 then 
      id = room:askToChoosePlayers(player, targets, 1, 1, "#zy__julue_ex_choose", self.name, false)
    elseif #targets == 1 then
      id = targets[1]
    end
    if id then
      local to = room:getPlayerById(id)
      local num = math.min(to.maxHp, 20) - to:getHandcardNum()
      if not to.dead and num > 0 then
        local mark = {id, num}
        if to ~= player then
          room:setPlayerMark(player, "zy__julue-record-turn", mark)
        end
        to:drawCards(num, self.name)
      end
    end
  end,
}
local julue_refresh = {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and not player.dead and player:getMark("zy__julue-record-turn") ~= 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(player:getMark("zy__julue-record-turn")[1])
    local num = player:getMark("zy__julue-record-turn")[2]
    local card = Fk:cloneCard("savage_assault")
    if not player:prohibitUse(card) and not player:isProhibited(to, card) and to:isAlive() then
      for i = 1, num do
        if not player:prohibitUse(card) and not player:isProhibited(to, card) and to:isAlive() then
          player.room:useVirtualCard("savage_assault", {}, player, to, self.name)
        else
          break
        end
      end
    end
  end
}
julue:addEffect(fk.AfterCardsMove, julue_)
julue:addEffect(fk.TurnEnd, julue_refresh)
return julue